<!Doctype html>
<html>

<head>
    <title>oixan的博客</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="Content-Type" content="text/html"  charset="utf-8">
    <meta name="referrer" content="no-referrer" />
    <link rel="stylesheet" type="text/css" href="../css/blog.css">

</head>

<body>
    <div class="head">
        <div class="headnav">
            <div class="naveframe">
                <ul class="navlist">
                    <li>
                        <a href="../index.html">
                            主页
                        </a>
                    </li>
                    <li>
                        <a href="../bloglist.html">
                            博客
                        </a>
                    </li>
                    <li>
                        <a href="../about.html">
                            关于
                        </a>
                    </li>
                </ul>
            </div>
        </div>

        <div class="headtext">
            <div class="headtext1">世界很简单，人类很复杂。</div>
            <div class="headtext2">浮生若梦，寻寻觅觅。</div>
        </div>
    </div>

    <div class="contents-all">
        <div class="contents">

            <div class="frame">
                <div class="title">
                    <h3>vba设置excel打开登录窗</h3>
                </div>
                <div class="dtime">时间：2018-11-02</div>
                <div class="detail">
      
                    <ol class=" list-paddingleft-2" style="list-style-type: decimal;">
                        <li>
                            <p>
                                按alt+f11弹出宏编辑，双击ThisWorkbook<br/>
                            </p>
                            <p>
                                声明那里选择workbook，输入代码
                            </p>
                            <p>
                                Private Sub Workbook_Open()
                            </p>
                            <p>
                                Application.Visible = False
                            </p>
                            <p>
                                For i = 1 To Sheets.Count - 1
                            </p>
                            <p>
                                Sheets(i).Visible = False
                            </p>
                            <p>
                                Next
                            </p>
                            <p>
                                UserForm1.Show
                            </p>
                            <p>
                                End Sub
                            </p>
                        </li>
                        <li>
                            <p>
                                添加用户窗体，分别添加两个标签（帐号；密码）和文字框，
                            </p>
                            <p>
                                和两个按钮（确定；取消），双击确定如下代码
                            </p>
                            <p>
                                Private Sub CommandButton1_Click()
                            </p>
                            <p>
                                Dim userid As String
                            </p>
                            <p>
                                Dim userpw As String
                            </p>
                            <p>
                                userid = TextBox1.Text
                            </p>
                            <p>
                                userpw = TextBox2.Text
                            </p>
                            <p>
                                If userid = &quot;ad&quot; And userpw = &quot;123&quot; Then
                            </p>
                            <p>
                                MsgBox (&quot;登录成功！&quot;)
                            </p>
                            <p>
                                UserForm1.Hide
                            </p>
                            <p>
                                For i = 1 To Sheets.Count - 1
                            </p>
                            <p>
                                Sheets(i).Visible = True
                            </p>
                            <p>
                                Next
                            </p>
                            <p>
                                Application.Visible = True
                            </p>
                            <p>
                                Else
                            </p>
                            <p>
                                MsgBox (&quot;帐号或密码错误！&quot;)
                            </p>
                            <p>
                                End If
                            </p>
                            <p>
                                End Sub
                            </p>
                            <p>
                                双击取消按钮，输入代码
                            </p>
                            <p>
                                Private Sub CommandButton2_Click()
                            </p>
                            <p>
                                ThisWorkbook.Saved = True
                            </p>
                            <p>
                                ThisWorkbook.Close
                            </p>
                            <p>
                                End Sub
                            </p>
                        </li>
                    </ol>
    
          
              </div>
                <a href="javascript:void(0)" onclick="showPg()">返回</a>
            </div>

        </div>
    </div>
    <div class="footer">
        <div class="footertext">©2018,oixan博客</div>
    </div>
    <span id="backtop" onclick="topFunction()">返回顶部</span>
    
</body>
<script  src="../js/fanhuiye.js"></script>

</html>